package com.chengxiaoxiao.dao.impl;

import com.chengxiaoxiao.dao.PublisherDao;
import com.chengxiaoxiao.domain.Publisher;
import com.chengxiaoxiao.utils.db.BeanHandler;
import com.chengxiaoxiao.utils.db.BeanListHandler;
import com.chengxiaoxiao.utils.db.DBAssist;
import com.chengxiaoxiao.utils.db.DBCPUtil;

import java.util.List;

public class PublisherDaoImpl implements PublisherDao {
    private DBAssist da = new DBAssist(DBCPUtil.getDataSource());

    @Override
    public void add(Publisher publisher) {
        da.update("insert into publisher(name) values(?)", publisher.getName());
    }

    @Override
    public void update(Publisher publisher) {
        da.update("update publisher set name=? where id=?", publisher.getName(), publisher.getId());
    }

    @Override
    public void delete(long id) {
        da.update("delete from publisher where id=?", id);
    }

    @Override
    public List get() {
        return (List) da.query("select * from publisher",new BeanListHandler(Publisher.class));
    }

    @Override
    public Publisher getbyId(long id) {
        return (Publisher) da.query("select * from publisher where id=?",new BeanHandler(Publisher.class),id);
    }

    @Override
    public List getListPage(int startIndex, int pageSize) {
        return null;
    }
}
